<template>
  <!-- // 分配角色 -->
  <div>
     <el-checkbox-group v-model="roleIds">
      <el-checkbox :label="item.id" v-for="item in list" :key="item.id">{{item.name}}</el-checkbox>
      
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="hConirm">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getSttings,allSttings } from '@/api/settings'
import { headPortraits } from '@/api/user'
export default {
  props:{
    id:{
      type:String,
      required:true
    }
  },
  data() {
    return {
      roleIds: [],
      list:[]
    }
  },
  created(){
    this.loadSettings()
  },
  methods: {
    // 分配权限
   async loadAllSttings(){
    try {
      const res = await allSttings({id:this.id,roleIds:this.roleIds})
      console.log(res);
    } catch (error) {
      console.log(error);
    }
    },
    // // 确定
    hConirm(){
      this.loadAllSttings()
      this.$emit('close');
    },
    
    // 获取员工列表
    async loadSettings(){
      try {
        const res = await getSttings({page:1,pagesize:100})
        // console.log('getSttings', res) 
        this.list=res.data.rows
       const info =  await headPortraits(this.id)
       this.roleIds=info.data.roleIds ||[]
      //  console.log(info);
        // 保存数据
      } catch (err) {
        console.log('getSttings', err)
      }
    },
    closeDialog() {
        this.$emit('close');
    }
  }
}
</script>